<template>
  <div class="children">
    <el-dialog title="审核" :visible.sync="$parent.openaudit" width="75%">
      <div class="center_dialog">
        <el-divider>基本信息</el-divider>
        <el-descriptions direction="vertical" :column="4" border size="medium">
          <el-descriptions-item label="申请单号">{{ ObjData.upkeepPlanNum || '-' }}</el-descriptions-item>
          <el-descriptions-item label="标题">{{ ObjData.title || '-' }}</el-descriptions-item>
          <el-descriptions-item label="负责人">{{ ObjData.headName || '-' }}</el-descriptions-item>
          <el-descriptions-item label="所属部门">{{ ObjData.deptName || '-' }}</el-descriptions-item>

          <el-descriptions-item label="循环类型">{{ ['循环保养', '单次保养'][ObjData.cycleType] || '-' }}</el-descriptions-item>
          <el-descriptions-item label="指定日期">{{ ObjData.specifyTime || '-' }}</el-descriptions-item>
          <el-descriptions-item label="生成任务">{{ ['提前一日', '提前二日', '提前三日', '提前四日', '提前五日'][ObjData.generateTaskType] ||
          '-'
          }}
          </el-descriptions-item>
          <el-descriptions-item label="验收人">{{ ObjData.acceptorName || '-' }}</el-descriptions-item>

          <el-descriptions-item label="验收人部门">{{ ObjData.acceptanceDeptName || '-' }}</el-descriptions-item>
          <el-descriptions-item label="验收方式" :span="4">{{ ObjData.acceptanceModeName || '-' }}</el-descriptions-item>
        </el-descriptions>
        <el-divider>保养设备</el-divider>
        <el-table v-loading="loading" :data="noticeList">
          <el-table-column label="序号" align="center" prop="order" width="50" />
          <el-table-column label="设备编号" align="center" min-width="130">
            <template slot-scope="scope">
              {{ scope.row.equipmentNum || '-' }}
            </template>
          </el-table-column>
          <el-table-column label="设备名称" align="center" min-width="130">
            <template slot-scope="scope">
              {{ scope.row.equipmentName || '-' }}
            </template>
          </el-table-column>
          <el-table-column label="品牌" align="center" min-width="130">
            <template slot-scope="scope">
              {{ scope.row.brand || '-' }}
            </template>
          </el-table-column>
          <el-table-column label="规格型号" align="center" min-width="130" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.model || '-' }}
            </template>
          </el-table-column>
          <el-table-column label="供应商" align="center" min-width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.supplierName || '-' }}
            </template>
          </el-table-column>
          <el-table-column label="单位" align="center" min-width="120">
            <template slot-scope="scope">
              <span>{{ scope.row.unitName || '-' }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center" min-width="180" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.remark || '-' }}
            </template>
          </el-table-column>
          <el-table-column align="center" min-width="220">
            <template slot="header">
              <!-- <span style="color:red">*</span>  -->
              循环起算日
            </template>
            <template slot-scope="scope">
              {{ scope.row.specifyTime || '-' }}
              <!-- <el-date-picker v-model="scope.row.specifyTime" type="date" style="width:217px" value-format="yyyy-MM-dd"
                      placeholder="请选择指定日期" /> -->
            </template>
          </el-table-column>
          <el-table-column label="保养标准" min-width="180" fixed="right" align="center">
            <template slot-scope="scope">
              <el-button size="small" type="primary" icon="el-icon-view" @click="handleSelect(scope.row)">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize" @pagination="getList" />
        <el-divider>审核信息</el-divider>
        <el-input type="textarea" v-model="form.view" placeholder="请填写审核意见" :rows="4"></el-input>
      </div>
      <div align="center" slot="footer" class="dialog-footer">
        <el-button type="success" @click="submitAudit('2')">通过</el-button>
        <el-button type="danger" @click="submitAudit('3')">驳回</el-button>
      </div>
    </el-dialog>
    <!-- 查看保养项目 -->
    <template v-if="openObject">
      <SelectStandard :row="rowObject"></SelectStandard>
    </template>
  </div>
</template>

<script>
import { getSelectChildrenPlan, getSelectChildrenPlanEquipment, CommitAuditUpkeepPlan } from '@/api/maintenance/insurance/insurance.js'

export default {
  props: ['rowObj'],
  components: {
    SelectStandard: () => import('../../ChildrenCreated/SelectStandard.vue')
  },
  data () {
    return {
      form: {
        "auditId": undefined, //审核信息ID
        "applicationId": undefined, //调拨ID
        "status": undefined, //状态（2已通过 3已驳回）
        "view": undefined //审核意见
      },
      ObjData: {},
      // 总条数
      total: 0,
      openObject: false,
      rowObject: {},
      loading: false,
      noticeList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'equipmentAccountId',
        isAsc: 'desc'//倒叙
      },
    }
  },
  created () {
    this.getList()
    this.getChildrenPlan()
  },
  methods: {
    /**
     * 初始化
     */
    async getList () {
      let params = {
        ...this.queryParams,
        'params[scope1]': 1,
        'params[scope4]': 1,
        'params[upkeepPlanId]': this.rowObj.upkeepPlanId //保养计划ID
      }
      this.loading = true
      let data = await getSelectChildrenPlanEquipment(params)
      this.noticeList = data && data.data.map((item, index) => {
        return {
          ...item,
          order: index + 1
        }
      })
      this.total = data.total
      this.loading = false
    },
    async getChildrenPlan () {
      let res = await getSelectChildrenPlan(this.rowObj.upkeepPlanId)//保养计划ID
      this.ObjData = res.data
    },
    handleSelect (row) {
      this.rowObject = { ...row, upkeepPlanId: this.rowObj.upkeepPlanId }
      this.openObject = true
    },
    /**
     * 提交
     */
    submitAudit (condition) {
      if ((!this.form.view) && condition === '3') return this.$message.error('驳回时审核意见不可为空')

      let params = {
        auditId: this.rowObj.audit && this.rowObj.audit.auditId,
        applicationId: this.rowObj.allocationId,
        status: condition,
        view: this.form.view
      }
      CommitAuditUpkeepPlan(params).then(res => {
        this.$parent.openaudit = false
        this.$message.success(res.msg)
        this.$parent.getList()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.center_dialog {
  // text-align: center;
  width: 90%;
  // padding: 0 10% 0 10%;
  box-sizing: border-box;
  margin: 0px auto;
}

.accep_flex {
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>